package com.shop.controller;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.shop.service.AdminService;
import com.shop.service.impl.AdminServiceImpl;


@WebServlet("/login.do")
public class loginServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		AdminService as = new AdminServiceImpl();
		String account = request.getParameter("account");
		String password = request.getParameter("password");
		Map<String,Object> result = as.selectAdmin(account, password);
		if(result.get("loginAdmin")!=null) {
			HttpSession session = request.getSession();
			session.setAttribute("loginAdmin", result.get("loginAdmin"));
			response.sendRedirect("Goods.do");
		}else {
			request.setAttribute("msg", result.get("msg"));
			request.getRequestDispatcher("login.jsp").forward(request, response);
		}
	}

	
	

}
